#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from MOMA.MOMA_V1.uitls.bs4_v1.crawlers import Bs4_v1, bs4


class Bs4_v1_ip(Bs4_v1):
    """
    爬取输入企业ip
    """

    def run_core(self):
        """
        执行任务
        :return:
        """
        bs4_obj = self.get_text()
        return self.get_ip(bs4_obj)

    def get_ip(self, get_ip_obj: bs4.element.ResultSet) -> str | None:
        """
        利用chinaz获取IP
        :param get_ip_obj:
        :return:
        """
        try:
            tmp_obj = get_ip_obj.find(name="div", attrs={"class": "fr zTContrig"})
            ip = tmp_obj.span.a.get_text()

            self.url_list.append(ip)
            return self.url_list[0]
        except AttributeError as err:
            print("爬取不到网页IP---{}".format(err))
